package org.lmind.example.uc.webapp;

import java.util.ArrayList;
import java.util.Collection;

import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.SecurityMetadataSource;
import org.springframework.security.web.FilterInvocation;
import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;

public class CustomSecurityMetadataSource implements FilterInvocationSecurityMetadataSource {
	
	private ArrayList<ConfigAttribute> attributes = new ArrayList<ConfigAttribute>();

	public CustomSecurityMetadataSource() {
		attributes.add(new CustomConfigAttribute("ConfigAttribute"));
	}

	@Override
	public Collection<ConfigAttribute> getAttributes(Object object)
			throws IllegalArgumentException {
		ArrayList<ConfigAttribute> ret = new ArrayList<ConfigAttribute>();
		ret.add(new CustomConfigAttribute(object.toString()));
		return ret;
	}

	@Override
	public Collection<ConfigAttribute> getAllConfigAttributes() {
		return null;
	}

	@Override
	public boolean supports(Class<?> clazz) {
		return FilterInvocation.class.isAssignableFrom(clazz);
	}
	
	public class CustomConfigAttribute implements ConfigAttribute {
		
		private String attribute;

		public CustomConfigAttribute(String attribute) {
			this.attribute = attribute;
		}

		@Override
		public String getAttribute() {
			return attribute;
		}
	}

}
